package cn.wubo.redis.controller;

import cn.wubo.redis.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/serRedis")
public class SerRedisController {

    @Autowired
    @Qualifier("redisTemplate")
    private RedisTemplate redisTemplate;

    @RequestMapping(value = "/testSerializableClass", method = RequestMethod.GET)
    public User testSerializableClass(String key) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key, User.getSampleUser());
        return (User) valueOperations.get(key);
    }
}
